package com.ipan.weixin.msg;

import java.io.Serializable;

import com.ipan.weixin.util.WxJsonBinder;

/**
 * JSON消息基类
 * 
 * @author iPan
 * @version 2013-12-26
 */
public abstract class AbstractJsonMsg implements JsonMsg, Serializable {
	
	/**
	 * serialVersionUID
	 */
	private static final long serialVersionUID = 544042475795645626L;
	protected static WxJsonBinder normalBinder = WxJsonBinder.buildNormalBinder();
	protected static WxJsonBinder nonNullBinder = WxJsonBinder.buildNonNullBinder();

	public String toJson() {
		return normalBinder.toJson(this);
	}
	
	public JsonMsg fromJson(String jsonString) {
		return fromJson(jsonString, this.getClass());
	}
	
	@Override
	public String toString() {
		return toJson();
	}
	
	public static <T> T fromJson(String jsonString, Class<T> clazz) {
		return normalBinder.fromJson(jsonString, clazz);
	}
}
